package com.alvinlkk.basic.chapter21;


public class SerialNumberGenerator {
    
    private static volatile int serivalNumber = 0;
    
    public synchronized static int nextSerialNumber() {
        return serivalNumber ++;   //volatile不能保证自增的原子性，要用synchronized进行同步
    }
}
